package org.simpleframework.singleton;

public class EnumSingleton {
    private EnumSingleton(){

    }

    public static EnumSingleton getInstance(){
        return ContainerHolder.HOLDER.instance;
    }

    private enum ContainerHolder{
        HOLDER;
        private EnumSingleton instance;
        ContainerHolder(){
            instance = new EnumSingleton();
        }
    }
    // 反编译后，生成的枚举类为
    /*private static final class ContainerHolder extends Enum{
        public static final ContainerHolder HOLDER;
        private EnumInstance instance;
        private static final ContainerHolder $VALUES[];
        static {
            // 类加载的时候，实例已经被创建
            HOLDER = new ContainerHolder("HOLDER",0);
            $VALUES = (new ContainerHolder[]{HOLDER});
        }
        private ContainerHolder(String s,int i){
            super(s,i);
            instance = new EnumInstance();
        }
    }*/
}
